﻿using System.Collections.Generic;
using System.Linq;
using NeuralLib;

namespace NEATlib
{
    public static class NeuralNetworkConstructor
    {
        public static DisconnectedNetwork NetworkFromGenome(Genom genom, NeuralNetworkInfo nninfo)
        {
            var neurons = genom.Neurons.Select(n => n.ToDisconnectedNeuron()).ToList();

            var connections = new List<Connection>();
            for (int i = 0; i < genom.Connections.Count; i++)
            {
                var connection = genom.Connections[i];
                if (connection.IsDisabled)
                    continue;
                var input = neurons.First(n=>n.Id == connection.InputNeuronId);
                var output = neurons.First(n => n.Id == connection.OutputNeuronId);
                connections.Add(new Connection(input, output, connection.Weight));
            }

            return new DisconnectedNetwork(neurons, connections);
        }
    }
}